package com.shensi.adminCollect.service.label.impl;

import com.shensi.adminCollect.common.exception.CustomException;
import com.shensi.adminCollect.common.utils.DateUtils;
import com.shensi.adminCollect.domain.label.LabelRule;
import com.shensi.adminCollect.mapper.label.LabelRuleMapper;
import com.shensi.adminCollect.service.label.ILabelRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 标签规则
Service业务层处理
 * 
 * @author qujia
 * @date 2021-06-15
 */


@Service
public class LabelRuleServiceImpl implements ILabelRuleService 
{
    @Autowired
    private LabelRuleMapper labelRuleMapper;



    @Override
    public List<LabelRule> selectLabelRuleListForQ(LabelRule labelRule) {
        return labelRuleMapper.selectLabelRuleListForQ(labelRule);
    }
    /**
     * 查询标签规则

     * 
     * @param id 标签规则
ID
     * @return 标签规则

     */
    @Override
    public LabelRule selectLabelRuleById(Integer id)
    {
        return labelRuleMapper.selectLabelRuleById(id);
    }

    /**
     * 查询标签规则
列表
     * 
     * @param labelRule 标签规则

     * @return 标签规则

     */
    @Override
    public List<LabelRule> selectLabelRuleList(LabelRule labelRule)
    {
        return labelRuleMapper.selectLabelRuleList(labelRule);
    }

    /**
     * 新增标签规则

     * 
     * @param labelRule 标签规则

     * @return 结果
     */
    @Override
    public int insertLabelRule(LabelRule labelRule)
    {
        labelRule.setCreateTime(DateUtils.getNowDate());
        return labelRuleMapper.insertLabelRule(labelRule);
    }

    /**
     * 修改标签规则

     * 
     * @param labelRule 标签规则

     * @return 结果
     */
    @Override
    public int updateLabelRule(LabelRule labelRule)
    {
        labelRule.setUpdateTime(DateUtils.getNowDate());
        return labelRuleMapper.updateLabelRule(labelRule);
    }

    /**
     * 批量删除标签规则

     * 
     * @param ids 需要删除的标签规则
ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteLabelRuleByIds(Integer[] ids)
    {
        if(ids==null||ids.length==0){
            throw new CustomException("ids不能为空");
        }
        Integer count=labelRuleMapper.selectCountAuditByIds(ids);
        if(count>0){
            throw new CustomException("存在未处理的渠道审核，渠道不能删除");
        }
            labelRuleMapper.deleteCustomerLabel(ids);
        return labelRuleMapper.deleteLabelRuleByIds(ids);
    }

    /**
     * 删除标签规则
信息
     * 
     * @param id 标签规则
ID
     * @return 结果
     */
    @Override
    public int deleteLabelRuleById(Integer id)
    {
        return labelRuleMapper.deleteLabelRuleById(id);
    }

    @Override
    public Integer countInReviewAudit(Integer id) {
        Integer[] ids=new Integer[1];
        ids[0]=id;
        return labelRuleMapper.selectCountAuditByIds(ids);
    }
}
